package com.tien.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.tien.dao.TestDao;
import com.tien.model.Admins;
import com.tien.model.Asset;
import com.tien.service.TestService;
import com.tien.utils.AbstractAction;
import com.tien.utils.CallBackJSONUtil;

/**
 * 
 * @author tien
 * 
 */
@Controller
@Scope("prototype")
public class TestAction extends AbstractAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6806654451336581261L;
	@Autowired
	private TestService testService;

	private String accountId;

	private List<Asset> assets;

	private List<Admins> admins;

	public String execute() {
		try {
			if (accountId == null || accountId == "")
				accountId = "tien";
			assets = testService.getAssets(accountId,
					Integer.parseInt(this.getStart()),
					Integer.parseInt(this.getLimit()));
			int count = testService.getAssertsCount(accountId);
			this.doSetPagingBean(count);
			Thread.sleep(1000);
		} catch (Exception e) {
		}
		return SUCCESS;
	}

	public String findAdminsList() {
		admins = testService.getAdmins(Integer.parseInt(this.getStart()),
				Integer.parseInt(this.getLimit()));
		int count = testService.getAdminsCount();
		try {
			this.doSetPagingBean(count);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "admins";
	}

	public String testAOPTransaction() {
		try {
			testService.saveTestAopTransactions();
			CallBackJSONUtil.printSuccessState(null, response);
		} catch (Exception e) {
			CallBackJSONUtil.printErrorState(e, response);
		}
		return null;
	}

	public List<Asset> getAssets() {
		return assets;
	}

	public void setAssets(List<Asset> assets) {
		this.assets = assets;
	}

	public String getAccountId() {
		return accountId;
	}

	public void setAccountId(String accountId) {
		this.accountId = accountId;
	}

	public List<Admins> getAdmins() {
		return admins;
	}

	public void setAdmins(List<Admins> admins) {
		this.admins = admins;
	}

}
